﻿<?php
	error_reporting(E_ALL^E_NOTICE);
	require_once ('./config/config.php'); 
	require_once ('./class/email.class.php'); 
	require_once ('./class/tools.class.php');
	date_default_timezone_set("PRC");
	session_start();
	if(empty($_SESSION['user'])){
		echo "<script>location='./login.php';</script>";
		exit();
	}else{
		$userRs=mysqli_fetch_array(mysqli_query($con,"select * from user where user='".$_SESSION['user']."'"));
		if($_POST['submit']){
			$book_name=$_POST['book_name'];
			$book_cover=stripslashes($_POST['book_cover']);
			$book_back=stripslashes($_POST['book_back']);
			$book_price=$_POST['book_price'];
			$book_class_id=$_POST['book_class_id'];
			mysqli_query($con,"INSERT INTO `book_sharing` (`bid`, `book_name`, `book_cover`, `book_back`, `book_price`, `book_class_id`, `uid`, `inspect`, `state`) VALUES (NULL, '".$book_name."', '".$book_cover."', '".$book_back."', '".$book_price."', '".$book_class_id."', '".$userRs['uid']."', '0', '0')");
			echo "<script>alert('图书发布成功，请等待管理员审核！');location='./my.php';</script>";
		}
	}
?>
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
<!--<![endif]-->
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>某高校图书共享网站</title>
		<meta name="description" content="A responsive web app template with common components like profile, list, tabs, menu views. Made for Codrops exclusively.">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<link rel="stylesheet" href="./assets/output.css">
		<link rel="stylesheet" href="./assets/node_modules/tippy.js/dist/themes/light.css">
		<link rel="stylesheet" href="./layui/css/layui.css">
		<script src="./layui/js/layui.js" v="layui" e="layui"></script>
		<link rel="stylesheet" href="./editor/plugins/code/prettify.css" />
		<script charset="utf-8" src="./editor/kindeditor-all-min.js"></script>
		<script charset="utf-8" src="./editor/lang/zh-CN.js"></script>
		<script charset="utf-8" src="./editor/plugins/code/prettify.js"></script>
		<script>
			KindEditor.ready(function(K) {
				var editor1 = K.create('textarea[name="book_cover"]', {
					cssPath : './editor/plugins/code/prettify.css',
					uploadJson : './editor/php/upload_json.php',
					fileManagerJson : './editor/php/file_manager_json.php',
					allowFileManager : true,
					afterCreate : function() {
						var self = this;
						K.ctrl(document, 13, function() {
							self.sync();
							K('form[name=example]')[0].submit();
						});
						K.ctrl(self.edit.doc, 13, function() {
							self.sync();
							K('form[name=example]')[0].submit();
						});
					}
				});
				var editor1 = K.create('textarea[name="book_back"]', {
					cssPath : './editor/plugins/code/prettify.css',
					uploadJson : './editor/php/upload_json.php',
					fileManagerJson : './editor/php/file_manager_json.php',
					allowFileManager : true,
					afterCreate : function() {
						var self = this;
						K.ctrl(document, 13, function() {
							self.sync();
							K('form[name=example]')[0].submit();
						});
						K.ctrl(self.edit.doc, 13, function() {
							self.sync();
							K('form[name=example]')[0].submit();
						});
					}
				});
				prettyPrint();
			});
		</script>
	</head>
	<body class="bg-grey-lighter font-sans antialiased">
		<!--[if lt IE 7]>
			<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p>
		<![endif]-->
		<div class="bg-indigo-darker text-center p-4 px-6 flex items-center">
			<div class="hidden lg:block lg:w-1/4 xl:w-1/5 pr-8">
				<font color="#ffffff"><h1>某高校图书共享网站</h1></font>
			</div>
		</div>
		<!-- Main -->
		<div class="flex">
			<!-- Content -->
			<div class="flex flex-1 flex-col md:px-6 pt-10" id="content">
				<!-- Title -->
				<div class="px-6 md:px-0 flex justify-between items-center -order-1">
					<div>
						<h2 class="font-normal"><a href="./index.php">首页</a> / <a href="./my.php">个人中心</a> / 发布图书</h2>
					</div>
					<p>欢迎您，<?php echo $_SESSION['user'];?> !</p>
				</div>
				<!-- Desktop Stats -->
				<div class="hidden px-6 md:px-0 mt-4 md:flex flex-wrap order-1 md:-order-1 md:shadow-md js-tab-pane" id="section-stats">
					<div class="p-4 px-6 w-full md:w-1/2 rounded md:rounded-r-none bg-white shadow-md md:shadow-none">
						<form action="push.php" method="post">
							<table class="mt-4 w-full">
								<p class="p-2 text-sm leading-loose border-b text-indigo">
									帐号：<?php echo $_SESSION['user'];?>
								<br />
									图书分类：<select name="book_class_id" class="layui-input" placeholder="请输入图书名称">
										<?php
											$class=mysqli_query($con,"select * from book_class order by cid asc");
											while($classRs=mysqli_fetch_array($class)){
												echo "<option value='".$classRs['cid']."'>".$classRs['class_name']."</option>";
											}
										?>
									</select>
								<br />
									图书名称：<input type="text" name="book_name" class="layui-input" placeholder="请输入图书名称">
								<br />
									图书封皮：（仅限一张照片）<textarea id="editor_id" name="book_cover" style="width:100%;height:300px;visibility:hidden;" placeholder="请输入内容"></textarea>
								<br />
									图书背皮：（仅限一张照片）<textarea id="editor_id" name="book_back" style="width:100%;height:300px;visibility:hidden;" placeholder="请输入内容"></textarea>
								<br />
									图书价格：<input type="text" name="book_price" class="layui-input" placeholder="请输入图书价格">
								<br />
									<input type="submit" name="submit" class="layui-btn" value="提交发布">
								</p>
							</table>
						</form>
					</div>
					<div class="w-full md:w-1/2 p-4 md:pt-12 md:pl-1 mt-4 md:mt-0 lg:pt-12 lg:pl-8 rounded md:rounded-r-none bg-white shadow-md md:shadow-none">
						<div class="flex">
						</div>
					</div>
				</div>
			</div>
		</div>
		<script src="./assets/bundle.js" async defer></script>
</body>
</html>